﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.BLL;
using System.Data;
using CMP.ERP.Model;

namespace CMP.ERP.Admin.Controllers
{
    /// <summary>
    /// 商品信息
    /// </summary>
    public class BlurbController : Controller
    {
        //
        // GET: /Blurb/
        //实例化对象
        CMP.ERP.BLL.CommodityBLL bll = new CommodityBLL();
        CMP.ERP.BLL.Role_Option1BLL rbll = new Role_Option1BLL();

        /// <summary>
        /// 显示商品
        /// </summary>
        /// <returns></returns>
        public ActionResult Blurb_Show()
        {
            ViewBag.CommodityType_Id = new SelectList(bll.GetCommodityTypeAll(), "CommodityType_Id", "CommodityType_Name");
            return View(bll.GetCommodityAll());
        }
        /// <summary>
        /// 实现添加商品信息功能
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public ActionResult AddComodity(Commodity c)
        {
            if(bll.AddCommodity(c)>0)
            {
                return Content("<script>alert('添加成功！'); location.href='/Blurb/Blurb_Show'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败！'); location.href='/Blurb/Blurb_Show'</script>");
            }
        }
        /// <summary>
        /// 实现删除商品功能
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult DelComodity(int id)
        {
            if (bll.DelCommodity(id) > 0)
            {
                return Content("<script>alert('删除成功！'); location.href='/Blurb/Blurb_Show'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败！'); location.href='/Blurb/Blurb_Show'</script>");
            }
        }
        /// <summary>
        /// 获取ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult GetCommodityById(int id)
        {

            Commodity cc = bll.GetCommodityById(id);
            ViewBag.CommodityType_Id = new SelectList(bll.GetCommodityTypeAll(), "CommodityType_Id", "CommodityType_Name",cc.CommodityType_Id);
            return View(cc);
        }
        /// <summary>
        /// 实现修改商品
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public ActionResult EditDo(Commodity c)
        {
            if (bll.EditCommodity(c) > 0)
            {
                return Content("<script>alert('修改成功！'); location.href='/Blurb/Blurb_Show'</script>");
            }
            else
            {
                return Content("<script>alert('修改失败！'); location.href='/Blurb/Blurb_Show'</script>");
            }
        }
        /// <summary>
        /// 按名称查找商品
        /// </summary>
        /// <param name="Commodity_Name"></param>
        /// <returns></returns>
        public ActionResult SearchByName(string Commodity_Name)
        {
            ViewBag.CommodityType_Id = new SelectList(bll.GetCommodityTypeAll(), "CommodityType_Id", "CommodityType_Name");

            return View("Blurb_Show", bll.SearchByName(Commodity_Name));
        }
        
    }
}
